package 寒假刷题;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 矩阵中的幸运数 {
    public List<Integer> luckyNumbers (int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[] rows = new int[m];
        int[] cols = new int[n];
        Arrays.fill(rows,Integer.MAX_VALUE);
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                rows[i] = Math.min(rows[i],matrix[i][j]);
                cols[j] = Math.max(cols[j],matrix[i][j]);
            }
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (cols[j]==rows[i])
                    list.add(rows[i]);
            }
        }
        return list;
    }
}
